#include "memmap.h"
#include <stdio.h>
#include "hexdump.h"

#define BSPMD_DISPLAY_BYTE_WIDTH 16

static int bspmm_real(unsigned long startAddr, unsigned long endAddr, unsigned long value)
{
	unsigned long ul_addr = 0;
	void *p_mem  = NULL;
	unsigned long len,i;

    ul_addr = startAddr;
	len = endAddr - startAddr;

	p_mem = memmap(ul_addr, len);
	if (p_mem == NULL)
    {
		printf("Memory Map error");
        return -1;
    }
	
    for (i = 0; i<len; i+=4)
    {
        *(unsigned int *)(p_mem + i) = value;
    }
	

	return 0;
}

int bspmm(int argc, char *argv[])
{
    unsigned long startAddr, endAddr, value;
    
    if (3 == argc)
    {
        sscanf(argv[1], "%lx", &startAddr);
        sscanf(argv[2], "%lx", &value);
        endAddr = startAddr + 4;
        bspmm_real(startAddr, endAddr, value);
    }
    else if (4 == argc)
    {
        sscanf(argv[1], "%lx", &startAddr);
        sscanf(argv[2], "%lx", &endAddr);
        sscanf(argv[2], "%lx", &value);
        bspmm_real(startAddr, endAddr, value);
    }
    else 
    {
        printf("Use: bspmm startAddr [endAddr] value\n");
    }
    return 0;
}